﻿using System;
using System.IO;

namespace Red.Scripts.Project.Generator.Solution
{
    public class Template
    {
        public string SourceFile { get; set; }
        public string Text { get; set; }
        public Guid ProjectInstanceGuid { get; set; }

        public void Read()
        {
            Text = File.ReadAllText( SourceFile );

            Text = Text.Replace( @"<ProjectTypeGuid>", Defines.Guids.Project.Raw );
            Text = Text.Replace( @"<ProjectInstanceGuid>", ProjectInstanceGuid.ToString().ToUpper() );
        }

        public void Write( string target )
        {
            if ( File.Exists( target ) )
            {
                File.SetAttributes( target, FileAttributes.Normal );
                File.Delete( target );
            }

            File.WriteAllText( target, Text );
        }
    }
}
